home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / e / eiffel.lha / flc / source / class.e < prev    next >
Encoding:
Text File  |  1996-01-21  |  6.3 KB  |  229 lines

  1.  
  2. -> Copyright © 1995, Guichard Damien.
  3.  
  4. -> Eiffel classes (top-most language abstraction)
  5.  
  6. -> Class is the upper Eiffel language abstraction.
  7. -> As genericity is not yet supported classes are also types.
  8. -> The 'is_heir_of' method is the foundation of the conformity management.
  9. -> The inheritance information is flattened into products of prime numbers.
  10. -> Each class has a unique prime number identifier.
  11. -> Then this prime number is multiplied by the prime of it parents.
  12. -> So a class is a parent of another if its prime product divides the other.
  13. -> ANY is a special class with prime_id=1   so every class inherit from ANY
  14. -> NONE is a special class with prime_id=0  so any class is a parent of NONE
  15.  
  16. -> TO DO :
  17. ->   generic classes/types
  18. ->   expanded classes/types
  19. ->   anchored types
  20. ->   multiple inheritance
  21. ->   repeated inheritance and selection
  22. ->   more stuff for obsolete classes
  23.  
  24. OPT MODULE
  25.  
  26. MODULE '*strings'
  27. MODULE '*treed_entity','*entity_tree'
  28. MODULE '*eiffel_lex'
  29. MODULE '*ame','*feature'
  30.  
  31. -> In a system, a class is either a client or a supplier
  32. -> This dictinction avoid compilation of unused client classes
  33. -> So a CLIENT class is not compiled, whereas a SUPPLIER class MUST be
  34. EXPORT ENUM CLIENT,SUPPLIER
  35.  
  36. -> Features of all classes are placed in a binary hash tree for quick search
  37. -> Classes still behave as each of them had their own features
  38. DEF features:PTR TO entity_tree
  39.  
  40. -> Next static link to class routine
  41. DEF static:PTR TO INT
  42.  
  43. -> class
  44. EXPORT OBJECT class OF treed_entity PUBLIC
  45.   status:CHAR                   -> client/supplier
  46.   is_deferred:CHAR              -> is class deferred?
  47.   has_creators:CHAR             -> has it a creators section?
  48.   lex:PTR TO eiffel_lex         -> lexical analyser
  49. PRIVATE
  50.   variables:INT                 -> number of variable attributs
  51.   routines:INT                  -> number of routines
  52.   to_be_redefined:CHAR          -> number of routines to be redefined
  53.   to_be_effected:CHAR           -> number of routines to be effected
  54. PRIVATE
  55.   parent:PTR TO class           -> parent of this class
  56.   prime_id:LONG                 -> class prime product identifier
  57.   label:INT                     -> class label
  58.   table:PTR TO INT              -> class jump table
  59. ENDOBJECT
  60.  
  61. -> This is not a kernel class.
  62. PROC is_kernel_class() OF class IS FALSE
  63.  
  64. -> Base class of the class-type
  65. PROC base() OF class IS self
  66.  
  67. -> Set class name
  68. PROC set_name(name,prime,label) OF class
  69.   IF features=NIL THEN NEW features
  70.   self.int:=hash(name)
  71.   self.name:=clone(name)
  72.   self.prime_id:=prime
  73.   self.status:=CLIENT
  74.   self.label:=label
  75. ENDPROC
  76.  
  77. -> Turn class into a supplier if needed
  78. -> Requires the class to named
  79. PROC supplier() OF class
  80.   DEF lex:PTR TO eiffel_lex
  81.   IF self.status=CLIENT
  82.     self.lex:=NEW lex.attach_text(self.name)
  83.     self.status:=SUPPLIER
  84.   ENDIF
  85. ENDPROC
  86.  
  87. -> Set class as deferred
  88. PROC defer() OF class
  89.   self.is_deferred:=TRUE
  90. ENDPROC
  91.  
  92. -> ALL following methods require class to be a supplier
  93.  
  94. -> Add 'parent' to parent list of this class.
  95. PROC add_parent(parent:PTR TO class) OF class
  96.   self.parent:=parent
  97.   self.prime_id:=Mul(self.prime_id,parent.prime_id)
  98.   self.variables:=self.variables+parent.variables
  99.   self.routines:=self.routines+parent.routines
  100.   self.to_be_effected:=self.to_be_effected+parent.to_be_effected
  101. ENDPROC
  102.  
  103. -> Add a feature to this class.
  104. PROC add_feature(feature:PTR TO feature) OF class
  105.   feature.set_class(self)
  106.   IF feature.is_variable()
  107.     self.variables:=self.variables+1
  108.     feature.set_count(self.variables)
  109.   ENDIF
  110.   IF feature.is_routine()
  111.     self.routines:=self.routines+1
  112.     feature.set_count(self.routines)
  113.   ENDIF
  114.   features.add(feature)
  115. ENDPROC
  116.  
  117. -> Redeclare a feature of this class.
  118. PROC redeclare_feature(feature:PTR TO feature) OF class
  119.   feature.set_class(self)
  120.   features.add(feature)
  121. ENDPROC
  122.  
  123. -> Find a feature named 'name' in this class, if possible.
  124. PROC find_feature(name) OF class
  125.   DEF f1:PTR TO feature
  126.   DEF f2=NIL:PTR TO feature
  127.   IF (f1:=features.find(name))=NIL THEN RETURN NIL
  128.   LOOP
  129.     IF self.is_heir_of(f1.class) THEN
  130.       f2:=IF f1.has_final_name() THEN f1 ELSE NIL
  131.     IF (f1:=features.continu(f1,name))=NIL THEN RETURN f2
  132.   ENDLOOP
  133. ENDPROC
  134.  
  135. -> One feature undefined.
  136. PROC undefine() OF class
  137.   self.to_be_effected:=self.to_be_effected+1
  138. ENDPROC
  139.  
  140. -> One feature to be redefined.
  141. PROC redefine() OF class
  142.   self.to_be_redefined:=self.to_be_redefined+1
  143. ENDPROC
  144.  
  145. -> One feature redefined.
  146. PROC redefined() OF class
  147.   self.to_be_redefined:=self.to_be_redefined-1
  148. ENDPROC
  149.  
  150. -> One feature to be effected.
  151. PROC effecting() OF class
  152.   self.to_be_effected:=self.to_be_effected+1
  153. ENDPROC
  154.  
  155. -> One deferred feature effected.
  156. PROC effected() OF class
  157.   self.to_be_effected:=self.to_be_effected-1
  158. ENDPROC
  159.  
  160. -> Prepare class in order to link routines.
  161. PROC prepare_links() OF class
  162.   DEF sup:PTR TO INT
  163.   DEF inf:PTR TO INT
  164.   DEF counter
  165.   IF self.routines
  166.     inf:=NewR(self.routines*SIZEOF INT)
  167.     self.table:=inf
  168.     IF self.parent
  169.       IF sup:=self.parent.table
  170.         FOR counter:=1 TO self.parent.routines
  171.           inf[]++:=sup[]++
  172.         ENDFOR
  173.       ENDIF
  174.     ENDIF
  175.   ENDIF
  176. ENDPROC
  177.  
  178. -> Are all features redefined?
  179. PROC all_redefined() OF class
  180. ENDPROC self.to_be_redefined=0
  181.  
  182. -> Are all features effected?
  183. PROC all_effected() OF class
  184. ENDPROC self.to_be_effected=0
  185.  
  186. -> Link a routine label to class vector.
  187. PROC link_routine(vector,label) OF class
  188.   self.table[vector-1]:=label
  189. ENDPROC
  190.  
  191. -> Label of first routine, 0 if none.
  192. PROC first_routine() OF class
  193.   IF self.routines=0 THEN RETURN 0
  194.   static:=self.table
  195. ENDPROC static[]++
  196.  
  197. -> Label of next routine, 0 if none.
  198. PROC next_routine() OF class
  199.   IF static-self.table/SIZEOF INT>=self.routines THEN RETURN 0
  200. ENDPROC static[]++
  201.  
  202. -> The class has a creators section.
  203. PROC creators_section() OF class
  204.   self.has_creators:=TRUE
  205. ENDPROC
  206.  
  207. -> Is class a heir of 'other'?
  208. PROC is_heir_of(other:PTR TO class) OF class
  209.   IF other.prime_id=0 THEN RETURN self.prime_id=0  -> NONE conforms to NONE!
  210. ENDPROC Mod(self.prime_id,other.prime_id)=0
  211.  
  212. -> Entity value access mode
  213. -> Use connected with AME code generation
  214. PROC access() OF class IS M_LABEL
  215.  
  216. -> Index for access to entity value
  217. -> Use connected with AME code generation
  218. PROC index() OF class IS self.label
  219.  
  220. -> Use connected with AME code generation
  221. PROC fields() OF class IS self.variables
  222.  
  223. -> Destructor
  224. PROC end() OF class
  225.   IF self.name THEN DisposeLink(self.name)
  226.   self.lex.end()
  227. ENDPROC
  228.  
  229.